<?php

namespace App\Home\Controllers;

use App\Home\Filters\WorshipHymnFilter;
use App\Home\Models\WorshipHymn;
use App\Home\Requests\WorshipHymnRequest;
use App\Home\Resources\WorshipHymnResource;
use Illuminate\Http\Request;

class WorshipHymnController extends Controller
{
    public function store(
        WorshipHymnRequest $request, 
        WorshipHymn $worshipHymn
    ){
        $inputs = $request->validated();
        $worshipHymn = $worshipHymn->add($inputs);

        return $this->created(WorshipHymnResource::make($worshipHymn));
    }

    public function update(
        WorshipHymnRequest $request, 
        WorshipHymn $worshipHymn
    ){
        $inputs = $request->validated();
        $worshipHymn->update($inputs);

        return $this->created(WorshipHymnResource::make($worshipHymn));
    }

    public function destroy(
        WorshipHymn $worshipHymn
    ){
        $worshipHymn->delete();
        return $this->noContent();
    }

    public function index(
        WorshipHymnRequest $request,
        WorshipHymnFilter $filter
    ){
        $fields = [
            "*",
        ];
        $worshipHymns = WorshipHymn::query()
            ->filter($filter)
            ->select($fields)
            ->paginate();

        return $this->ok(WorshipHymnResource::collection($worshipHymns));
    }

    public function show(
        Int $id
    ){
        $fields = [
            "*",
        ];
        $worshipHymn = WorshipHymn::query()
            ->select($fields)
            ->find($id);
        return $this->ok(WorshipHymnResource::make($worshipHymn));
    }
}
